#pragma once

#include <iostream>
#include <memory>
#include "Protocol.hpp"

class NetCal
{
private:
public:
    NetCal()
    {
    }

    std::shared_ptr<Response> Calculator(std::shared_ptr<Request> req)
    {
        auto resp = Factory::BuildResponseDefault();
        int x = req->GetX();
        int y = req->GetY();
        switch (req->GetOper())
        {
        case '+':
            resp->SetResult(x + y);
            break;
        case '-':
            resp->SetResult(x - y);
            break;
        case '*':
            resp->SetResult(x * y);
            break;
        case '/':
            {
                if (y == 0)
                {
                    resp->SetCode(1);
                    resp->SetDesc("div zero");
                }
                else
                {
                    resp->SetResult(x / y);
                }
            }
            break;
        case '%':
            {
                if (y == 0)
                {
                    resp->SetCode(2);
                    resp->SetDesc("mod zero");
                }
                else
                {
                    resp->SetResult(x % y);
                }
            }
            break;
        default:
            {
                resp->SetCode(3);
                resp->SetDesc("Illegal operation");
            }
            break;
        }
        return resp;
    }

    ~NetCal()
    {
    }

private:
};
